Repository navigation
Conversation
There was a problem hiding this comment.
🔵 Needs a closer look
Security-sensitive constant-time arithmetic changes across ECC, six SP backends, and assembly implementations require specialist cryptographic review and target-specific correctness and side-channel validation beyond source inspection.
No open issues 🎉
What changed in this PR
This PR strengthens side-channel protection in wolfCrypt’s SAKKE implementation through constant-time arithmetic and cache-resistant lookups, with an optional RNG interface for blinding.
Changes:
- Harden secret-dependent P1024 operations across supported backends and use constant-time reduction in ECC point mapping.
- Add the
wc_SetSakkeRng()interface, documentation, and tests for blinded operations. - Correct x86 AVX2 table-read bounds, add vector-state cleanup, and adjust P1024 guards and key-generation buffer sizing.
| File | Description |
|---|---|
wolfssl/wolfcrypt/sakke.h |
Declare the RNG setter and store a non-owned RNG pointer. |
wolfssl/wolfcrypt/ecc.h |
Allow extra random bytes to reduce key-generation bias. |
wolfcrypt/test/test.c |
Test RNG setter arguments and repeat SAKKE operations with blinding. |
wolfcrypt/src/sp_x86_64.c |
Harden P1024 lookups, multiplication, and exponentiation. |
wolfcrypt/src/sp_x86_64_asm.S |
Add AVX2 lookups, fix read bounds, and clear upper vector state. |
wolfcrypt/src/sp_x86_64_asm.asm |
Apply equivalent AVX2 changes to Windows assembly. |
wolfcrypt/src/sp_riscv64.c |
Harden RISC-V P1024 lookups and secret exponentiation. |
wolfcrypt/src/sp_c64.c |
Harden portable 64-bit P1024 operations. |
wolfcrypt/src/sp_c32.c |
Harden portable 32-bit P1024 operations. |
wolfcrypt/src/sp_armthumb.c |
Harden ARM Thumb P1024 operations. |
wolfcrypt/src/sp_arm64.c |
Harden ARM64 P1024 operations. |
wolfcrypt/src/ecc.c |
Keep constant-time point mapping in Montgomery form until final conversion. |
doc/dox_comments/header_files/sakke.h |
Document RNG configuration, ownership, and intended performance benefits. |
doc/dox_comments/header_files/doxygen_groups.h |
Recommend RNG setup in SAKKE usage flows. |
Review effort: Balanced
|
f121bbe to
05cff92
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
Constant-time changes across five arithmetic backends and two assembly formats require human security review and target-specific correctness and side-channel validation beyond the supplied configure-only testing.
No open issues 🎉
Review effort: Balanced
6a7bfe1 to
e039009
Compare
e4a326d to
ac74e92
Compare
|
Jenkins: retest this please |
d88b9a8 to
7423f01
Compare
|
Code generated with: |
|
Jenkins: retest this please |
1 similar comment
|
Jenkins: retest this please |
7423f01 to
ac4bc76
Compare
- Without an RNG, operations on secrets (z_T, RSK, r) are constant time: reduction, inversion, field add/sub, ModExp and point mapping. - New wc_SetSakkeRng(): blinding allows faster algorithms to be used. wc_MakeSakkeRsk() uses it rather than instantiating an RNG per call. Blinding values are generated by SAKKE rather than wc_ecc_gen_k() so the ECC random buffer size (ECC_MAXSIZE_GEN in FIPS v6) doesn't limit them. - Table lookups cache resistant unless WC_NO_CACHE_RESISTANT. - SP P1024: constant time lookups (AVX2 on x86_64), table multiply and ModExp; fix AVX2 entry over-read, add vzeroupper; fix p1024_order guard for NO_ECC_CHECK_KEY builds. - ecc_map_ex() constant time branch uses constant time reduction. - ECC generic projective add/double: constant time Montgomery reduction and point equality check when timing resistant. Public only operations (ecc_mul2add(), verify) keep the faster reduction. - sp_int: sp_invmod_mont_ct() reductions are constant time; cheaper constant time final subtraction and input masking in Montgomery reduction. - TFM: honor the constant time flag of Montgomery reduction (plain reduction unchanged unless WOLFSSL_MONT_RED_CT), fixed length carry propagation, constant time clamp, fp_invmod_mont_ct() constant time reductions; fix fp_submod_ct() leaving a stale top digit. - ECCSI signing: r * SSK, HE + r * SSK, inversion and multiply by j are constant time (Fermat inversion in Montgomery form) with TFM and SP math all; other math builds keep blinded inversion. - Public only operations use the faster multiplication: ECCSI verify (non-SP curves) computes Y and J with ecc_mul2add(), and the public key order check uses ecc_mul2add() (uncached when FP_ECC). - Regenerate SP x86_64 assembly (32-bit parameters zero extended). - SP Karatsuba squaring (ARM, RISC-V): |a_lo - a_hi| by constant time negation rather than selecting operand pointers by the secret sign. - SP point add: doubling check and infinity masks read through volatiles so the compiler cannot branch on their parts. - Tests and docs for wc_SetSakkeRng(); white-box tests updated for changed static helpers.
ac4bc76 to
28a92ce
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #12120
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): .github/configs/os-check-linux.json, doc/ASM_AND_MATH_DEFINES.md, doc/dox_comments/header_files/doxygen_groups.h, doc/dox_comments/header_files/sakke.h, wolfcrypt/src/sp_arm32.c, wolfcrypt/src/sp_arm64.c, wolfcrypt/src/sp_armthumb.c, wolfcrypt/src/sp_cortexm.c, wolfcrypt/src/sp_x86_64.c, wolfcrypt/src/sp_x86_64_asm.S, wolfcrypt/src/sp_x86_64_asm.asm
Coverage: 12 of 14 in-scope changed file(s) opened by the reviewer; not opened: tests/unit-mcdc/test_sakke_fault_whitebox.c, tests/unit-mcdc/test_sakke_whitebox.c
Findings: 1
1 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Reported findings require changes before merge.
Review tier: Max
| #ifndef WOLFSSL_NO_CT_OPS | ||
| if (ct == 1) { | ||
| /* Zero digits at and above used without depending on used. */ | ||
| sp_int_digit aUsed = (sp_int_digit)a->used; |
There was a problem hiding this comment.
_sp_mont_red constant-time input mask truncates used and the digit index to 8 bits when SP_WORD_SIZE=8 · Logic errors
With SP_WORD_SIZE=8, sp_int_digit is 8 bits, so casting a->used and i to it wraps both values at 256. For moduli of 1024 bits or more, the ct path then clears digits that hold data and keeps stale ones. This corrupts mp_montgomery_reduce_ct (RSA blinding removal, SAKKE) and sp_invmod_mont_ct; the replaced ctMaskIntGTE compared at int width.
Suggested fix: Compare i with a->used at unsigned int width, as the replaced ctMaskIntGTE call did, and only then narrow the resulting 0/1 to a full digit mask.
Basis: C11 6.3.1.3p2: converting a value to an unsigned integer type reduces it modulo one more than the type's maximum value, so an 8-bit sp_int_digit cannot hold indices of 256 or more.
Related known findings (similar but distinct; listed for context, not part of this finding)
- F-16439: that finding is
_sp_cond_copyapplying an 8-bit limb mask to theusedfield; this one is the ct input masking in_sp_mont_red, which compares a truncated index with a truncatedused.
Description
Fixes zd#22803
Testing
./configure --enable-sakke